<template>
	<!-- 登录页面，从超市app粘过来的 -->
	<view>
		<view class="title">店长app:</view>
		<view class="container">
			<view class="login-wrapper">
				<view class="form-wrapper">
					<input class="input-item" type="text"  placeholder="username" v-model="username" />
					<input class="input-item" type="text"  placeholder="password" v-model="password" password="true"/>
					<button type="default" class="button" @click="login">登录</button>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {userLogin} from '@/api/login/login.js'
	
	import {createConnection} from '@/utils/websocket.js'
	export default {
		data() {
			return {
				username:'',
				password:'',
			}
		},
		onShow() {
			// console.log('店长app的登录页面', this.$store.state.user.text)
		},
		methods: {
			/**
			 * 用户名：1
			 * 密码：123456
			 */
			async login() {
				// console.log(this.username, this.password)
				let res = await userLogin(this.username, this.password)
				res = res.data.result
				console.log('用户信息 = ', res)
				
				/* if (res.isadmin != 1) {
					uni.showToast({
					    title: '你不是管理员',
						icon:'none',
					    duration: 2000
					});
					return;
				} */
				
				// 把用户信息存储在store中
				this.$store.commit('user/set_userInfo', res)
				console.log('shopID = ', this.$store.state.user.userInfo.shopID)
				
				// 连接websocket
				createConnection(this.$store.state.user.userInfo.shopID)
				
				uni.switchTab({
					 url: '/pages/my/my'
				})
				
			}
		}
	}
</script>

<style lang="scss">
	.title{
		font-weight: bold;
		padding-left: 30rpx;
	}
.container{
		height: 1210rpx;
		// background-image: linear-gradient(to right,#fbc2eb,#a6c1ee);
		display: flex;
		justify-content: center;
		.login-wrapper{
			// background-color: #FFFFFF;
			width: 400rpx;
			height: 500rpx;
			padding: 0 50rpx;
			margin: 250rpx 0;
			border-radius: 10rpx;
		}
	}
	
	.input-item{
		border-bottom: 1rpx solid gray;
		margin-bottom: 20rpx;
	}
	.button{
		color: #FFFFFF;
		margin-top: 50rpx;
		background: #02a774;
		font-size: 33upx;
	}
</style>
